package com.tubi.HashMap;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashMapDemo1 {
    public static void main(String[] args) {
        HashMap<Student, String> hashMap = new HashMap<>(); //创建HashMap
        Student si= new Student("ronglei", 112);
        Student si1 = new Student("ronglei2", 112);
        Student si2 = new Student("ronglei2", 112);
        Student si3 = new Student("ronglei2", 12);


        hashMap.put(si, "上海");
        hashMap.put(si1, "上海23");
        hashMap.put(si2, "上海2");
        hashMap.put(si3, "上海22");

        //第一个循环
        //获取所有的key
        Set<Student> keys = hashMap.keySet();
        for (Student key : keys) {
            //获取keu的值
            String key1 = hashMap.get(key);
            System.out.println(key+"==="+key1);
        }

        //第二种 获取所有的键值对对象entrySet()
        Set<Map.Entry<Student, String>> entries = hashMap.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            Student key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+"====="+value);
        }
        //第三种循环
        hashMap.forEach(
                (Student key,String value)->{
                    System.out.println(key+"==="+value);
                }
        );
    }
}
